/*
 * Copyright (c) 2025 CAX Conversion Project
 */
package com.comac.ins.isfd.factory;

import com.comac.ins.common.core.exception.base.BaseException;
import com.comac.ins.isfd.constant.enums.IsfdMetadataTableNameEnum;
import com.comac.ins.isfd.service.IIsfdMetadataImportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.List;

/**
 * 元数据导入工厂
 *
 * @author hxloongs
 * @date 2024-9-24
 */
@Component
public class IsfdMetadataImportFactory {

    @Autowired
    private List<IIsfdMetadataImportService> iIsfdMetadataImportServiceList;

    public IIsfdMetadataImportService getMetadataImportServiceByTableName(IsfdMetadataTableNameEnum isfdMetadataTableNameEnum) {
        if (isfdMetadataTableNameEnum == null) {
            throw new BaseException("库类型不存在，请确认后重试！");
        }
        if (CollectionUtils.isEmpty(iIsfdMetadataImportServiceList)) {
            throw new BaseException("库类型不存在，请确认后重试！");
        }
        // 选择对应元数据导入实现类
        return iIsfdMetadataImportServiceList.stream()
                .filter(item -> item.selectByTableName().equals(isfdMetadataTableNameEnum.getValue()))
                .findFirst()
                .orElseThrow(() -> new BaseException("库类型不存在，请确认后重试！"));
    }
}
